<!--
 * @Author: Zhao Star
 * @LastEditors: Zhao Star
 * @Description: *******************
 * @Date: 2019-04-25 19:37:20
 * @LastEditTime: 2019-05-13 14:38:01
 -->
<template>
  <div class="recommend" ref="recommend">
    <scroll ref="scroll" class="recommend-content" :data="banners">
      <div>
        <div v-if="banners.length" class="slider-wrapper" ref="sliderWrapper">
          <slider>
            <div v-for="(item,index) in banners" :key="index">
              <!-- <a :href="item.linkUrl"> -->
              <img class="needsclick" @load="loadImage" :src="item.imageUrl">
              <!-- </a> -->
            </div>
          </slider>
        </div>
        <div class="loading-container" v-show="!banners.length">
          <loading></loading>
        </div>
      </div>
    </scroll>
  </div>
</template>

<script>
import Scroll from '@/base/scroll/scroll'
import Slider from '@/base/slider/slider'
import Loading from '@/base/loading/loading'
import { getBanner } from '@/api/banner.js'

export default {
  components: {
    Slider,
    Loading,
    Scroll
  },
  name: '',
  data() {
    return {
      banners: [],
      msg: {
        email: ' ',
        password: ' '
      }
    }
  },
  created() {
    getBanner().then(res => {
      this.banners = res.banners
      this.banners.push(this.banners[0])
    })
  },
  methods: {
    loadImage() {
      if (!this.checkloaded) {
        this.checkloaded = true
        this.$refs.scroll.refresh()
      }
    }
  }
}
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
@import '~@common/stylus/variable';

.recommend {
  position: fixed;
  width: 100%;
  top: 88px;
  bottom: 0;

  .recommend-content {
    height: 100%;
    overflow: hidden;

    .slider-wrapper {
      position: relative;
      width: 100%;
      overflow: hidden;
    }

    .recommend-list {
      .list-title {
        height: 65px;
        line-height: 65px;
        text-align: center;
        font-size: $font-size-medium;
        color: $color-theme;
      }

      .item {
        display: flex;
        box-sizing: border-box;
        align-items: center;
        padding: 0 20px 20px 20px;

        .icon {
          flex: 0 0 60px;
          width: 60px;
          padding-right: 20px;
        }

        .text {
          display: flex;
          flex-direction: column;
          justify-content: center;
          flex: 1;
          line-height: 20px;
          overflow: hidden;
          font-size: $font-size-medium;

          .name {
            margin-bottom: 10px;
            color: $color-text;
          }

          .desc {
            color: $color-text-d;
          }
        }
      }
    }

    .loading-container {
      position: absolute;
      width: 100%;
      top: 50%;
      transform: translateY(-50%);
    }
  }
}
</style>
